package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.ConfessionalWallComment;
import com.codedancer.campus.qo.confessionalWallComment.ConfessionalWallCommentPageSearchQo;

public interface ConfessionalWallCommentMapper extends BaseMapper<ConfessionalWallComment> {

    /**
     * 分页查询表白墙父级评论
     *
     * @param confessionalWallCommentPage
     * @param confessionalWallCommentPageSearchQo
     * @return
     */
    default IPage<ConfessionalWallComment> pageParentComment(
        Page<ConfessionalWallComment> confessionalWallCommentPage,
        ConfessionalWallCommentPageSearchQo confessionalWallCommentPageSearchQo) {
        LambdaQueryWrapper<ConfessionalWallComment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ConfessionalWallComment::getConfessionalWallUuid,
            confessionalWallCommentPageSearchQo.getConfessionalWallUuid());
        lambdaQueryWrapper.eq(ConfessionalWallComment::getParentUuid, "0");
        lambdaQueryWrapper.orderByDesc(ConfessionalWallComment::getCreateTime);
        return selectPage(confessionalWallCommentPage, lambdaQueryWrapper);
    }

    /**
     * 判断父级评论是否有儿子
     *
     * @param uuid
     * @return
     */
    default Boolean hasChildren(String uuid) {
        LambdaQueryWrapper<ConfessionalWallComment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ConfessionalWallComment::getParentUuid, uuid);
        return selectCount(lambdaQueryWrapper) > 0;
    }

    /**
     * 分页查询该评论下子集评论
     *
     * @param confessionalWallCommentPage
     * @param confessionalWallCommentPageSearchQo
     * @return
     */
    default IPage<ConfessionalWallComment> pageChildrenComment(
        Page<ConfessionalWallComment> confessionalWallCommentPage,
        ConfessionalWallCommentPageSearchQo confessionalWallCommentPageSearchQo) {
        LambdaQueryWrapper<ConfessionalWallComment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ConfessionalWallComment::getParentUuid,
            confessionalWallCommentPageSearchQo.getConfessionalWallCommentUuid());
        lambdaQueryWrapper.orderByDesc(ConfessionalWallComment::getCreateTime);
        return selectPage(confessionalWallCommentPage, lambdaQueryWrapper);
    }
}
